package com.itheima.d4_collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/*
    目标：斗地主游戏的案例开发。
    业务需求分析:
        业务: 总共有54张牌。
        点数: "3","4","5","6","7","8","9","10","J","Q","K","A","2"
        花色: "♠", "♥", "♣", "♦"
        大小王: "👲" , "🃏"
        点数分别要组合4种花色，大小王各一张。
        斗地主：发出51张牌，剩下3张作为底牌。
 */
public class GameDemo {
    public static void main(String[] args) {
        String[] numbers = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        String[] colors = {"♠", "♥", "♣", "♦"};
        int size = 0;
        ArrayList<Card> cards = new ArrayList<>();
        for (String number : numbers) {
            size++;
            for (String color : colors) {
                Card card = new Card(number, color, size);
                cards.add(card);
            }
        }
        Card card1 = new Card("", "🃏", ++size);
        Card card2 = new Card("", "👲", ++size);
        Collections.addAll(cards, card1, card2);
        System.out.println(cards);
        System.out.println("====================================");
        Collections.shuffle(cards);
        System.out.println(cards);
        ArrayList<Card> ming = new ArrayList<>();
        ArrayList<Card> wang = new ArrayList<>();
        ArrayList<Card> gang = new ArrayList<>();
        for (int i = 0; i < cards.size() - 3; i++) {
            Card card = cards.get(i);
            if (i % 3 == 0) {
                ming.add(card);
            } else if (i % 3 == 1) {
                wang.add(card);
            } else {
                gang.add(card);
            }
        }
        System.out.println("小明的牌" + ming);
        System.out.println("小王的牌" + wang);
        System.out.println("小刚的牌" + gang);

        Collections.sort(ming, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o2.getSize() - o1.getSize();
            }
        });
        Collections.sort(wang, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.getSize() - o2.getSize();
            }
        });
        Collections.sort(gang, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.getColor().compareTo(o2.getColor());
            }
        });
        System.out.println("====================================");
        System.out.println("小明的牌" + ming);
        System.out.println("小王的牌" + wang);
        System.out.println("小刚的牌" + gang);

        List<Card> list = cards.subList(cards.size() - 3, cards.size());
        System.out.println("底牌是"+list);

        ming.addAll(list);
        Collections.sort(ming, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o2.getSize() - o1.getSize();
            }
        });
        System.out.println("小明抢完地主的牌" + ming);
    }
}










